package model

import (
	"gorm.io/gorm"
	"time"
	"user_service/basic/config"
)

// 商品
type Good struct {
	Id        uint           `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	Name      string         `gorm:"column:name;type:varchar(255);comment:名称;not null;" json:"name"`                       // 名称
	Info      string         `gorm:"column:info;type:varchar(255);comment:简介;not null;" json:"info"`                       // 简介
	Stock     uint           `gorm:"column:stock;type:int UNSIGNED;comment:库存;not null;default:0;" json:"stock"`           // 库存
	Price     float64        `gorm:"column:price;type:decimal(10, 2);comment:价格;not null;" json:"price"`                   // 价格
	Status    uint           `gorm:"column:status;type:int UNSIGNED;comment:状态：1上架 2下架;not null;default:1;" json:"status"` // 状态：1上架 2下架
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletadAt gorm.DeletedAt `gorm:"column:deletad_at;type:datetime(3);default:NULL;" json:"deletad_at"`
}

func (g *Good) List() (goodList []*Good, err error) {
	err = config.DB.Order("created_at desc").Find(&goodList).Error
	return
}
